package com.taotao.manage.controller;



import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;


import com.taotao.manage.pojo.Item;
import com.taotao.manage.service.ItemDescService;
import com.taotao.manage.service.ItemService;
/*加载商品描述
 * $.getJSON('/rest/item/desc/'+data.id,function(_data){
 *  /**
	  * 
	  * 异步
	  * 参数 form表单
	  * 返回结果 响应状态码 201 400 500
	  */

@RequestMapping("/item/desc")
@Controller
public class ItemDescController {
	@Autowired
	private ItemService itemService;
	@Autowired
	private ItemDescService itemDescService;
	
	@RequestMapping(method=RequestMethod.POST)
	 public ResponseEntity<Void> saveItem(Item item, @RequestParam("desc") String desc){
		try {
			//TODO进行数据校验
			if (StringUtils.isEmpty(item.getTitle())) {
				//返回参数错误:400
				return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
			}
			//新增商品
			this.itemService.saveItem(item,desc);
			//201返回成功
			return ResponseEntity .status(HttpStatus.CREATED).build();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//500异常
		return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
	

}
